<template>
  <!-- 头部横幅 -->
  <div class="banner">
    <img :src="imageCover" class="banner-img">
    <div class="banner-content">
      <h1 class="banner-title">{{videoInfo.title}}</h1>
      <div class="banner-meta">
        <div class="banner-meta-item">
          <i class="fas fa-star"></i> {{videoInfo.rating}}分
        </div>
        <div class="banner-meta-item">
          <i class="fas fa-play"></i> {{videoInfo.viewCount}}播放
        </div>
        <div class="banner-meta-item">
          <i class="fas fa-heart"></i> {{videoInfo.viewCount}}追番
        </div>
        <div class="banner-meta-item">
          <i class="fas fa-calendar"></i> {{DateTime}}
        </div>
        <div class="banner-meta-item">
          <i class="fas fa-tv"></i> {{videoInfo.region}}
        </div>
      </div>
    </div>
  </div>

  <div class="container">
    <div class="main-content">
      <!-- 左侧主内容区 -->
      <div class="left-column">
        <!-- 基本信息卡片 -->
        <div class="info-card">
          <div class="basic-info">
            <div class="cover-container">
              <img :src="imageUrl" class="cover-img">
            </div>
            <div class="info-detail">
              <h2 class="info-title">{{videoInfo.title}}</h2>
              <div class="info-meta">
                <span class="info-meta-item highlight">★{{videoInfo.rating}}</span>
                <span class="info-meta-item">全{{videoInfo.episode}}话</span>
                <span class="info-meta-item">{{DateTime}}</span>
                <span class="info-meta-item">{{videoInfo.region}}</span>
              </div>
              <div class="tag-list">
                <span class="tag" v-for="tag in tags" :key="tag">{{ tag }}</span>
              </div>
              <div class="action-buttons">
                <button class="btn btn-primary" @click="goVideo">
                  <i class="fas fa-play"></i> 立即观看
                </button>
                <button class="btn btn-default">
                  <i class="fas fa-plus"></i> 追番
                </button>
                <button class="btn btn-default">
                  <i class="fas fa-share-alt"></i> 分享
                </button>
              </div>
            </div>
          </div>
        </div>

        <!-- 剧情简介卡片 -->
        <div class="info-card">
          <div class="card-header">
            <h3 class="card-title">剧情简介</h3>
          </div>
          <div class="description collapsed" id="description">
            {{videoInfo.introduction}}
          </div>
          <div class="toggle-btn" onclick="toggleDescription()">
            <span>展开全部</span>
            <i class="fas fa-chevron-down"></i>
          </div>
        </div>

        <!-- 角色介绍卡片 -->
        <div class="info-card">
          <div class="card-header">
            <h3 class="card-title">主要角色</h3>
          </div>
          <div class="character-list">
            <div class="character-card" v-for="item in mainCharacters" :key="item">
              <img src="@/assets/image/lbt1.png" class="character-avatar">
              <h4 class="character-name">{{item.cv}}</h4>
              <p class="character-role">{{ item.name }}</p>
            </div>
          </div>
        </div>
      </div>
      <!-- 右侧边栏 -->
      <div class="right-column">
        <!-- 制作人员卡片 -->
        <div class="info-card staff-card">
          <div class="card-header">
            <h3 class="card-title">制作人员</h3>
          </div>
          <div class="staff-item">
            <div class="staff-role">原作</div>
            <div class="staff-name">{{staff.originalAuthor}}</div>
          </div>
          <div class="staff-item">
            <div class="staff-role">监督</div>
            <div class="staff-name">{{staff.director}}</div>
          </div>
          <div class="staff-item">
            <div class="staff-role">系列构成</div>
            <div class="staff-name">{{staff.seriesComposer}}</div>
          </div>
          <div class="staff-item">
            <div class="staff-role">角色设计</div>
            <div class="staff-name">{{staff.characterDesigner}}</div>
          </div>
          <div class="staff-item">
            <div class="staff-role">音乐</div>
            <div class="staff-name">{{staff.music}}</div>
          </div>
        </div>
        <div class="info-card"></div>
      </div>
    </div>
  </div>
</template>
<script setup>
import {ref,onMounted} from "vue";
import {useRoute,useRouter} from "vue-router";
import {getVideoInfo} from "@/api/video.js";
import {imgUrl} from "@/utils/http.js";
import {routerURl} from "@/utils/Request.js";

const videoInfo = ref({
  title: "",
  cover: "",
  description: "",
  staff: [],
  tags: [],
  episodes: [],
  playUrl: "",
  rating: "",
  region: ""
})
const router = useRouter();
const route = useRoute();
const imageUrl = ref()
const imageCover = ref()
const DateTime = ref()
const tags = ref([])
const mainCharacters = ref([])
const staff = ref([])

//2025-04-07 00:00:00 => 2025年4月7日
const formatDateTime = (dateTime) => {
  const date = new Date(dateTime)
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  return `${year}年${month}月${day}日`
}

const videoData = async () => {
 const res = await getVideoInfo(route.params.id)
 videoInfo.value = res.data
  imageUrl.value = imgUrl + videoInfo.value.videoCover
  imageCover.value = imgUrl + videoInfo.value.videoChartCover
  DateTime.value = formatDateTime(videoInfo.value.releaseDate)
  tags.value = JSON.stringify(videoInfo.value.tags).replace(/\[|\]|\"/g, '').split(',')
  tags.value = tags.value.map(item => item.replace(/\\/g, ''))
 mainCharacters.value = JSON.parse(videoInfo.value.mainCharacters).map(item => ({
    cv: item.cv,
    name: item.name
  }))
  staff.value = JSON.parse(videoInfo.value.staff)
}

const goVideo = () =>{
  router.push({
    path: routerURl.videoPlay+route.params.id+'-1-1',
  })
}
onMounted(() => {
  videoData()
})
</script>
<style scoped>
* {
  box-sizing: border-box;
}
body {
  font-family: "PingFang SC","Microsoft YaHei",sans-serif;
  margin: 0;
  background: var(--bg-color);
  color: var(--text-dark);
  line-height: 1.6;
}
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 15px;
}

/* 头部横幅 */
.banner {
  position: relative;
  height: 240px;
  overflow: hidden;
  border-radius: 0 0 8px 8px;
  margin-bottom: 20px;
}
.banner-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: brightness(0.7);
}
.banner-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 30px;
  color: white;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
}
.banner-title {
  font-size: 28px;
  margin: 0 0 10px;
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.banner-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  font-size: 14px;
}
.banner-meta-item {
  display: flex;
  align-items: center;
}
.banner-meta-item i {
  margin-right: 5px;
  font-size: 16px;
}

/* 主要内容区 */
.main-content {
  display: flex;
  gap: 20px;
}
.left-column {
  flex: 1;
}
.right-column {
  width: 300px;
  flex-shrink: 0;
}

/* 番剧信息卡片 */
.info-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--card-shadow);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}
.card-title {
  font-size: 18px;
  font-weight: 500;
  margin: 0;
}

/* 基本信息 */
.basic-info {
  display: flex;
  gap: 20px;
}
.cover-container {
  flex: 0 0 180px;
}
.cover-img {
  width: 100%;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.info-detail {
  flex: 1;
}
.info-title {
  font-size: 22px;
  margin: 0 0 10px;
}
.info-meta {
  margin-bottom: 15px;
}
.info-meta-item {
  display: inline-block;
  margin-right: 15px;
  font-size: 14px;
  color: var(--text-gray);
}
.info-meta-item.highlight {
  color: var(--bili-blue);
  font-weight: 500;
}
.tag-list {
  margin: 15px 0;
}
.tag {
  display: inline-block;
  padding: 4px 10px;
  background: #f0f7ff;
  color: var(--bili-blue);
  border-radius: 4px;
  margin-right: 8px;
  margin-bottom: 8px;
  font-size: 12px;
}
.action-buttons {
  margin-top: 20px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  margin-right: 10px;
  transition: all 0.2s;
}
.btn-primary {
  background: var(--bili-pink);
  color: white;
  border: none;
}
.btn-primary:hover {
  background: #fa5a8a;
}
.btn-default {
  background: white;
  color: var(--text-dark);
  border: 1px solid #ddd;
}
.btn-default:hover {
  background: #f5f5f5;
}
.btn i {
  margin-right: 5px;
}

/* 剧情简介 */
.description {
  line-height: 1.8;
  color: #555;
}
.description.collapsed {
  max-height: 120px;
  overflow: hidden;
  position: relative;
}
.description.collapsed::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(transparent, white);
}
.toggle-btn {
  color: var(--bili-blue);
  cursor: pointer;
  font-size: 14px;
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
}
.toggle-btn i {
  margin-left: 5px;
  transition: transform 0.2s;
}
.toggle-btn.expand i {
  transform: rotate(180deg);
}

/* 角色介绍 */
.character-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 15px;
  margin-top: 15px;
}
.character-card {
  text-align: center;
}
.character-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto 8px;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.character-name {
  font-size: 14px;
  margin: 0;
}
.character-role {
  font-size: 12px;
  color: var(--text-gray);
  margin: 3px 0 0;
}

/* 右侧边栏 */
.staff-card {
  margin-bottom: 20px;
}
.staff-item {
  display: flex;
  margin-bottom: 12px;
}
.staff-role {
  width: 60px;
  color: var(--text-gray);
  font-size: 13px;
}
.staff-name {
  flex: 1;
  font-size: 14px;
}

/* 推荐番剧 */
.recommend-card {
  background: white;
  border-radius: 8px;
  padding: 15px;
  box-shadow: var(--card-shadow);
}
.recommend-item {
  display: flex;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px dashed #eee;
}
.recommend-item:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
.recommend-cover {
  width: 60px;
  height: 80px;
  border-radius: 4px;
  object-fit: cover;
  margin-right: 12px;
  flex-shrink: 0;
}
.recommend-info {
  flex: 1;
}
.recommend-title {
  font-size: 14px;
  margin: 0 0 5px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.recommend-meta {
  font-size: 12px;
  color: var(--text-gray);
}
.recommend-score {
  color: #FFB800;
  font-weight: bold;
}

/* 响应式设计 */
@media (max-width: 992px) {
  .main-content {
    flex-direction: column;
  }
  .right-column {
    width: 100%;
  }
  .banner {
    height: 180px;
  }
  .banner-content {
    padding: 20px;
  }
}
@media (max-width: 768px) {
  .basic-info {
    flex-direction: column;
  }
  .cover-container {
    margin: 0 auto 15px;
    max-width: 200px;
  }
  .character-list {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}
</style>